/**
 * 作者:李杰
 * email: maillijie@gmail.com
 */
package com.javainfo.actions.forums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.javainfo.simpledto.ArticleDto;
import com.javainfo.util.JavaInfoActionSupport;

public class SearchCtrl extends JavaInfoActionSupport{

	/** serialVersionUID */
	private static final long serialVersionUID = 1L;

	@Override
	public String index() throws Exception {
		return INDEX;
	}
	
	/**
	 * @return
	 */
	public String serachUser(){
		List<String> result = new ArrayList<String>();
		String start = getRequest().getParameter("start");
		List<String> accountList = getServiceFactory().getUserService()
				.getUserAccountListByStart(start);
		if (accountList != null) {
			result.addAll(accountList);
		}
		Map<String, Object> modelMap = new HashMap<String, Object>();
		modelMap.put("root", result);
		setModel(modelMap);
		return INDEX;
	}
	
	/**
	 * @return
	 */
	public String searchArticleByUserAccount(){
		String start = getRequest().getParameter("start");
		List<ArticleDto> articles = getServiceFactory().getArticleService().getArticlesByUserAccount(start);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("articles", articles);
		model.put("start", start);
		setModel(model);
		return INDEX;
	}
}
